package com.ckg.test;

import com.ckg.service.CartService;
import com.ckg.service.InventoryService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class EcommerceApp {
    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

        // 验证购物车服务作用域
        CartService cart1 = ctx.getBean("cartService", CartService.class);
        CartService cart2 = ctx.getBean("shoppingCart", CartService.class); // 使用别名获取
        System.out.println("购物车是否相同: " + (cart1 == cart2)); // 应输出？

        // 验证库存服务作用域
        InventoryService inv1 = ctx.getBean("inventoryService", InventoryService.class);
        InventoryService inv2 = ctx.getBean("inventoryService", InventoryService.class);
        inv1.reduceStock();
        inv2.reduceStock(); // 输出结果？

        // 测试购物流程
        CartService cart = ctx.getBean("cartService", CartService.class);
        cart.addToCart("iPhone15");
    }
}
